package com.ashleyleung.jetpack_b_station.api

import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import timber.log.Timber
import java.util.concurrent.TimeUnit

/**
 * @author lxy
 * @name 创建热太柔fit已经提供api servi
 * @class describe
 * @date 2022-06-28
 * Copyright (c)  Guangzhou GCI Science & Technology Co., Ltd.All rights reserved
 */
object RetrofitClient {


    val retrofit = Retrofit.Builder()
        .baseUrl(ApiService.baseUrl)
        .addConverterFactory(GsonConverterFactory.create())
        .client(getOkHttpClient())
        .build()

    val apiService = retrofit.create(ApiService::class.java)


    private fun getOkHttpClient(): OkHttpClient {


        //新建log拦截器
        val loggingInterceptor = HttpLoggingInterceptor { message ->
            Timber.i("http请求参数：%s", message)
        }
        // 日志显示级别
        loggingInterceptor.level = HttpLoggingInterceptor.Level.BODY


        return OkHttpClient.Builder()
            .callTimeout(300, TimeUnit.SECONDS)
            .addInterceptor(loggingInterceptor)
            .build()

    }

}